//
//  KRLTabBarController.m
//  KaraLive
//
//  Created by Zhijia Zhong on 2018/9/11.
//  Copyright © 2018年 naxigoren. All rights reserved.
//

#import "KRLTabBarController.h"
#import "KRLTabBar.h"
#import "KRLTimelineViewController.h"

@interface KRLTabBarController ()<KRLTabBarDelegate>

@end

@implementation KRLTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    KRLTabBar *tabBar = [[KRLTabBar alloc] init];
    tabBar.tintColor = [UIColor colorWithRGB:0xff9451];
    tabBar.delegate = self;
    [self setValue:tabBar forKey:@"tabBar"];
    
    KRLTimelineViewController *tvc = [[KRLTimelineViewController alloc] init];
    UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:tvc];

    UIViewController *vc2 = [[UIViewController alloc] init];
    vc2.view.backgroundColor = [UIColor grayColor];
    UIViewController *vc3 = [[UIViewController alloc] init];
    vc3.view.backgroundColor = [UIColor greenColor];
    UIViewController *vc4 = [[UIViewController alloc] init];
    vc4.view.backgroundColor = [UIColor redColor];
    UIViewController *vc5 = [[UIViewController alloc] init];
    vc5.view.backgroundColor = [UIColor blueColor];
    self.viewControllers = @[nvc1, vc2, vc3, vc4, vc5];
    
    nvc1.tabBarItem.title = @"Timeline";
    nvc1.tabBarItem.image = [UIImage imageNamed:@"tabbar_home"];
    nvc1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_home_pre"];

    vc2.tabBarItem.title = @"Discovery";
    vc2.tabBarItem.image = [UIImage imageNamed:@"tabbar_discovery"];
    vc2.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_discovery_pre"];

    [tabBar setCenterImage:[UIImage imageNamed:@"tabbar_sing"] selectedImage:[UIImage imageNamed:@"tabbar_sing_pre"]];
    
    vc4.tabBarItem.title = @"Message";
    vc4.tabBarItem.image = [UIImage imageNamed:@"tabbar_message"];
    vc4.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_message_pre"];

    vc5.tabBarItem.title = @"Profile";
    vc5.tabBarItem.image = [UIImage imageNamed:@"tabbar_mine"];
    vc5.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_mine_pre"];
}

- (void)tabBar:(KRLTabBar *)tabBar didSelectItem:(UITabBarItem *)item {
     tabBar.centerButton.selected = [tabBar.items indexOfObject:item] == 2;
}

- (void)tabBar:(KRLTabBar *)tabBar didSelectCenterItem:(UIButton *)item {
    self.selectedIndex = 2;
    item.selected = YES;
}

@end
